package com.jr.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jr.pojo.Dept;
import com.jr.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class TestController {

    @Autowired
    private DeptService deptService;

    @RequestMapping("/show")
//    @ResponseBody
    public String show(){
        return "hello";
    }

    @RequestMapping("/getall")
//    @ResponseBody
    public String getAll(Model model){
        return "list";
    }

    @PostMapping(value = "/ajaxgetall",produces = "application/json;charset=utf-8")
    @ResponseBody
    public List<Dept> ajaxgetall(){
        return deptService.findAll(null);
    }

    @GetMapping(value = "/getpageone",produces = "application/json;charset=utf-8")
    @ResponseBody
    public PageInfo<Dept> getPageOne(Integer indexpage,String queryname){
        PageHelper.startPage(indexpage,3);
        PageInfo<Dept> pageInfo = new PageInfo<>(deptService.findAll(queryname));
        return pageInfo;
    }

    @GetMapping("/test")
    @ResponseBody
    public String test(){
        return "hhh";
    }
}
